package com.tuling.JUC;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * @Type CyclicBarrierUtil.java
 * @Desc
 * @Author wzw
 * @Date 2024/9/10 14:18
 */
public class CyclicBarrierUtil {
    public static void main(String[] args) {

        ThreadLocal local = new ThreadLocal();

        CyclicBarrier cyclicBarrier = new CyclicBarrier(7,()->{
            System.out.println("程序加法计数器");
        });

        for (int i = 0; i <7 ; i++) {
            final int temp = i;
            new Thread(()->{
                    System.out.println(Thread.currentThread().getName() + "=>" + temp);
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } catch (BrokenBarrierException e) {
                    throw new RuntimeException(e);
                }
            }).start();
        }

        System.out.println("执行完成");

    }
}
